<template>
  <div class="login-wrapper">
    <main class="main" aria-label="主体区块">
      <div class="hidden-style">
        <input type="text">
        <input type="password">
      </div>
      <section class="contain">
        <div class="login-inner">
          <div class="login-left">
            <div id="animation" class="logo-animation">
<!--              <picture>-->
<!--                <source media="(min-width: 320px) and (max-width: 768px)"-->
<!--                        :srcset="'/test-management/system/common/others/login-object-bg02.png' | imgLoginHost">-->
<!--                <source media="(min-width: 768px)" :srcset="'/test-management/system/common/others/login-object-bg.png' | imgLoginHost">-->
<!--                <img :src="'/test-management/system/common/others/login-object-bg02.png' | imgLoginHost" alt="this is a picture">-->
<!--              </picture>-->
              <div class="logo-img">
                <img :src="'/test-management/system/common/others/login-object-logo.png' | imgLoginHost" alt=""></div>
              <div class="logo-light">
                <img :src="'/test-management/system/common/others/login-object-light.png' | imgLoginHost" alt="">
              </div>
              <div class="logo-right">
                <img :src="'/test-management/system/common/others/login-object-right.png' | imgLoginHost" alt="">
              </div>
              <div class="logo-left">
                <img :src="'/test-management/system/common/others/login-object-left.png' | imgLoginHost" alt="">
              </div>
            </div>
          </div>
          <div class="login-right">
            <!--logo-->
            <div class="login-logo">
              <img :src="(siteConfig ? siteConfig.logo : '/test-management/system/logo/CMSLogo.png') | imgLoginHost" alt="">
            </div>
            <el-form :model="loginForm" ref="loginForm" label-width="0" @keyup.enter="submitForm('loginForm')"
                     class="login-item" autocomplete="off">
              <el-form-item
                prop="account"
                :rules="[
                    { required: true, message: '请输入账号', trigger: 'blur' }
                  ]">
                <i v-show="loginForm.account.length > 0" class="el-icon-error right-icon"
                   @click="loginForm.account = ''"></i>
                <div class="login-input-box input-style01">
                  <div class="icon-img">
                    <img src="../../assets/img/person.png" alt="">
                  </div>
                  <el-input v-model="loginForm.account" autocomplete="off" placeholder="请输入账号"></el-input>
                </div>
              </el-form-item>
              <el-form-item
                prop="password"
                :rules="[{ required: true, message: '请输入密码', trigger: 'blur' } ]">
                <!--<i class="fa fa-lock input-icon" v-if="screenW <=768"></i>-->
                <i class="dafa-icon dafa-icon-eye03 right-icon" :class="eye ? 'dafa-icon-eye03' : 'dafa-icon-eye04'"
                   @click="eye = !eye"></i>
                <i v-show="loginForm.password.length > 0" class="el-icon-error right-icon x-icon"
                   @click="loginForm.password = ''"></i>
                <div class="login-input-box input-style01">
                  <div class="icon-img">
                    <img src="../../assets/img/lock.png" alt=""></div>
                  <el-input :type="!eye && isFocus ? 'password' : 'text'" @focus="isFocus = true" autocomplete="off" v-model="loginForm.password" placeholder="请输入密码"
                            @keyup.enter.native="submitForm('loginForm')"
                  ></el-input>
                </div>
              </el-form-item>
              <el-form-item
                prop="token"
                class="login-lastitems"
                v-if="siteConfig && siteConfig.isToken === 1"
                :rules="[
                    { required: true, message: '请输入口令', trigger: 'blur' }
                  ]">
                <i v-show="loginForm.token.length > 0" class="el-icon-error right-icon"
                   @click="loginForm.token = ''"></i>
                <div class="login-input-box input-style01">
                  <div class="icon-img"><img :src="'/test-management/system/common/others/d.png' | imgLoginHost" alt=""></div>
                  <el-input v-model="loginForm.token" placeholder="请输入令牌" autocomplete="off"></el-input>
                </div>
              </el-form-item>
              <el-form-item class="login-button">
                <div class="login-input-box input-style02  login-btn-box">
                  <el-button type="text" :loading="loading" @click="submitForm()">登 录</el-button>
                </div>
              </el-form-item>
            </el-form>
            <div class="login-message">{{loginResult}}</div>
          </div>
        </div>
        <div class="login-version">Cms 1.0 建议使用Google Chrome浏览器</div>
      </section>
    </main>
  </div>
</template>

<script>
import Api from '@/api/users.js'
export default {
  name: 'Index',
  filters: {
    imgLoginHost (v) {
      return 'https://images.imags-google.com/' + v
    }
  },
  data () {
    return {
      eye: false,
      isFocus: false,
      loginForm: {
        account: '',
        password: ''
      },
      loading: false,
      loginResult: ''
    }
  },
  computed: {
    siteConfig () {
      return this.$store.state.siteConfig
    }
  },
  methods: {
    submitForm () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.fetchInfo()
        }
      })
    },
    fetchInfo () {
      this.loading = true
      Api.login(this.loginForm).then((res) => {
        this.loading = false
        if (res.code === 200) {
          this.loginResult = '登录成功'
          let user = {
            account: this.loginForm.account,
            token: res.data
          }
          // res.data.tenantCode === 'system' ? res.data.isPlatform = 1 : res.data.isPlatform = 0
          this.$store.dispatch('setUserInfo', user)
          localStorage.setItem('token', res.data)
          let timer = setTimeout(() => {
            this.loginResult = '' // 登录提示清零
            let base = this.$route.query.redirect || '/'
            this.$router.replace(base)
            clearTimeout(timer)
          }, 200)
        } else if (res.code === -1) {
          this.msgError(res.msg)
        }
      })
    }
  }
}
</script>
<style>
  .hidden-style {
    display: none;
  }
  .contain {
    width: 100vw;
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    display: flex;
    min-height: 500px;
    align-items: center;
    z-index: 1000;
    justify-content: center;
  }

  .main {
    width: 100%;
    height: 100vh;
    min-height: 500px;
    background: url(../../assets/img/loginbg.jpg) center center /cover no-repeat;
    position: relative;
  }
  @media only screen and (max-width: 768px) {
    .login-contain .el-input__inner, .register input, .resetPassword input, .login-contain input:focus, .register input:focus, .resetPassword input:focus {
      font-size: 16px;
    }

    .contain{
      width: 100vw;
      display: block;
    }
    .main{
      background: linear-gradient(180deg, rgba(31, 50, 64, 1)0%, rgba(61, 87, 102, 1),rgba(45, 67, 82, 1));
      /*background: linear-gradient(180deg, rgba(48, 70, 86, 1)50%, rgba(64, 88, 105, 1),rgba(35, 55, 69, 1));   /*background: linear-gradient(180deg, rgba(48, 70, 86, 1)50%, rgba(64, 88, 105, 1),rgba(35, 55, 69, 1));*/
    }
  }
  .logo-animation {
    position: relative;
  & > div {
      position: absolute;
      top: 0;
      left: 0;
      display: block;
    }
  & .logo-img {
      z-index: 3;
      animation: mover01 2s infinite alternate;
    }
  & .logo-light {
      animation: mover02 0.5s infinite alternate;
    }
  & .logo-d {
      z-index: 3;
      animation: mover03 1s infinite alternate;
    }
  & .logo-right {
      z-index: 3;
      animation: moverRight 3s infinite alternate;
    }
  & .logo-left {
      z-index: 3;
      animation: moverLeft 4s infinite alternate;
    }
  }

  .login-inner {
    width: 65%;
    max-width: 1200px;
    min-height: 300px;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 80px 60px;
    box-shadow: -5px 2px 14px rgba(6, 6, 6, .1);
    background: linear-gradient(258deg, rgba(24, 45, 58, 1) 35%, rgba(44, 65, 79, 0.7) 90%);
  }

  .login-left {
    width: calc(100% - 350px);
    max-width: 670px;
  }

  .login-right {
    width: 350px;
    position: relative;
  }

  .icon-img {
    line-height: 22px;
  }

  .login-message {
    text-align: center;
    color: var(--color-danger);
    font-size: 14px;
    position: absolute;
    bottom: -30px;
    width: 100%;
    line-height: 20px;
    height: 20px;
    left: 0;
  }

  .login-logo {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 0 40px 0;
  }

  .login-item .el-form-item {
    margin-bottom: 8px !important;
    position: relative;
  & .el-form-item__error {
      left: 24px;
      top: 93%;
    }
  & .el-form-item__content {
  & .el-input {
      width: calc(100% - 22px) !important;
      line-height: normal;
  & input {
      width: 260px;
      font-size: 15px !important;
      border-left: 1px solid #50606b;
      border-bottom: none !important;
      border-top: none !important;
      border-right: none !important;
      background-color: transparent !important;
      color: #fff !important;
  &::placeholder {
     color: #9da6ac !important;
   }
  }
  & input:-webkit-autofill {
      -webkit-text-fill-color: #fff;
      background-color: transparent;
      -webkit-transition: background-color 10000s cubic-bezier(1, -100, 1, -100) 0s;
    }
  }
  & .input-style01 {
      background: url("../../assets/img/input.png") center center /cover no-repeat;
    }
  & .input-style02 {
      background: url("../../assets/img/login-btn.png") center center /cover no-repeat;
      transition: all .5s;
  &:hover {
     background: url("../../assets/img/login-btn-hover.png") center center /cover no-repeat;
   }
  & button {
      width: 100%;
      height: 100%;
      font-size: 16px;
      text-align: center !important;
      border: none !important;
      color: #fff !important;
      padding: 0 !important;
      font-weight: 300 !important;
      cursor: pointer;
      outline: none !important;
      box-shadow: none !important;
  &:before {
     display: none;
   }
  }
  }
  & .login-input-box {
      width: 100%;
      height: 68px;
      padding: 22px 24px;
      position: relative;
      display: inline-flex;
      justify-content: center;
      align-self: center;
  & img {
      width: 22px;
      height: 22px;
    }

  }
  & .login-btn-box {
      font-size: 20px;
      color: #fff;
      font-weight: 300;
      letter-spacing: 1px;
      cursor: pointer;
      margin-top: 20px;
  &:hover {
     color: #dddddd;
   }
  }
  & input {
      text-align: left !important;
      background: none !important;
      padding: 0 0 0 10px;
      margin-left: 10px;
      height: 25px !important;
      line-height: 25px !important;
      max-height: 25px !important;
      border-radius: 0px !important;
      border: 1px solid #75828a !important;
    }
  }
  & .input-icon {
      position: absolute;
      z-index: 3;
      font-size: 20px !important;
      color: #fff;
      top: 50%;
      transform: translate(0, -50%);
      line-height: 16px;
      left: -1px;
      width: 35px;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  & .right-icon {
      position: absolute;
      right: 30px;
      z-index: 2;
      color: #aaabab;
      top: 50%;
      transform: translate(0, -50%);
      cursor: pointer;
      opacity: 1;
  &:hover {
     opacity: 0.6;
   }
  }
  & .x-icon {
      right: 58px !important;
    }
  }

  .login-item .el-form-item .input-icon.smaller-icon {
    font-size: 16px !important;
    margin: 0 0 0 -1px;
  }

  .login-button .el-button--primary {
    padding: 13px 15px !important;
  }

  .login-version {
    position: absolute;
    bottom: 50px;
    color: #fff;
    opacity: 0.3;
    font-size: 12px;
  }

  .hidden-style {
    display: none;
  }

  @media only screen and (max-width: 1440px) {
    .login-right {
      width: 276px;
    }

    .login-left {
      width: calc(100% - 300px);
    }

    .login-inner {
      padding: 60px;
    }

    .login-input-box {
      width: 100% !important;
      height: 50px !important;
      padding: 20px 24px;
      display: flex;
      align-items: center;
  & img {
      width: 18px !important;
      height: 18px !important;
    }

  }

  .login-logo {
    padding: 0 0 30px 0;
    width: 100%;
    max-width: 180px;
    margin: 0 auto;
  }

  .login-item .el-form-item__content {
  & .login-btn-box {
      padding: 0 !important;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 15px !important;
    }
  & .el-input input {
      width: 160px !important;
    }
  & .right-icon {
      right: 25px !important;
    }
  & .x-icon {
      right: 50px !important;
    }
  }

  }

  @media only screen and (max-width: 1024px) {
    .login-inner {
      width: 90%;
    }

    .login-version {
      bottom: 20px;
      text-align: center;
      width: 100%;
    }
  }

  @media only screen and (max-width: 768px) {
    .icon-img {
      position: relative;
      top: -2px;
    }
    .login-inner {
      width: 100%;
      display: block;
      padding: 46% 0 0 0 !important;
      background: none;
      position: relative;
      box-shadow: none;
  & > div {
      width: 100% !important;
    }
  & .login-right {
      position: relative;
      width: 90% !important;
      margin: 0px auto;
      padding: 60px 5px;
      box-shadow: -5px 2px 14px rgba(6, 6, 6, .1);
  &:after {
     content: '';
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
     display: block;
     position: absolute;
     z-index: 0;
     opacity: 0.97;
     background: linear-gradient(90deg, rgba(47, 67, 81, 1), rgba(25, 46, 60, 1));
   }
  }
  & .login-logo img {
      width: 180px;
      max-height: 70px;
    }
  & .login-logo, & .login-item {
                     position: relative;
                     z-index: 1;
                   }
  & .login-left {
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1;
    }
  }

  .logo-animation {
    margin: 0 auto;
    width: 90%;
  }

  .login-item {
    width: 98%;
    margin: 0 auto;
    max-width: 320px;
  & .el-form-item__content .el-input {
      position: relative;
  &:after {
     position: absolute;
     content: '';
     left: 8px;
     top: 10px;
     width: 1px;
     height: 20px;
     background: #354957;
   }
  & input {
      border-left: none !important;
      font-size: 15px !important;
      position: relative;
    }

  }
  }

  .login-inner .el-form-item.is-success .el-input__inner, .login-inner .el-form-item.is-success .el-input__inner:focus, .login-inner .el-form-item.is-success .el-textarea__inner, .login-inner .el-form-item.is-success .el-textarea__inner:focus {
    border: none !important;
  }
  /*.input-style01 {*/
  /*  background: url("../../assets/img/login-input01.png") center center /cover no-repeat !important;*/
  /*}*/

  /*.input-style02 {*/
  /*  background: url("../../assets/img/login-btn-phone.png") center center /cover no-repeat !important;*/
  /*}*/

  .login-input-box {
    padding: 7px 23px !important;
  }
  }

  @media only screen and (max-width: 320px) {
    .login-right {
      padding: 40px 0px !important;
      min-width: 310px;
    }

    .login-version {
      bottom: 15px;
    }

    .login-inner {
      padding: 23% 0 0 0 !important;
    }

  }

  @media screen and (max-height: 450px) and (max-width: 768px) {
    .login-version {
      bottom: 15px;
    }

    .login-inner {
      padding: 50px 0 0 0 !important;

  & .login-right {
      margin: 0px auto;
      padding: 30px;
  &:after {
     opacity: 1;
   }
  }
  }

  }

  @keyframes mover01 {
    0% {
      transform: translateY(0);
      opacity: 0.3;
    }
    100% {
      transform: translateY(10px);
      opacity: 1;
    }
  }

  @keyframes mover02 {
    0% {
      opacity: 0.7;
    }
    100% {
      opacity: 1;
    }
  }

  @keyframes mover03 {
    0% {
      opacity: 0.5;
    }
    100% { opacity: 0.8;}
  }

  @keyframes moverRight {
    0% {
      transform: translate(0px, 0)
    }
    100% {
      transform: translate(1%, 1%)
    }
  }

  @keyframes moverLeft {
    0% {
      transform: translate(0px, 0px);
    }
    100% {
      transform: translate(1%, -1%);
    }
  }
</style>
